package com.leyou.controller;

import com.leyou.api.R;
import com.leyou.dao.CategoryDao;
import com.leyou.entity.CategoryEntity;
import com.leyou.service.CategoryService;
import com.leyou.vo.catelogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    @RequestMapping("/getCname")
    public R getCategoryAllNameByid(@RequestParam("cid1") Long cid1 ,
                                    @RequestParam("cid2") Long cid2 ,
                                    @RequestParam("cid3") Long cid3 ){
        String cname = categoryService.getCategoryAllNameByid(cid1, cid2, cid3);
        return R.ok().put("data",cname);
    }


    @RequestMapping("/list")
    public List<CategoryEntity> getListlevl(@RequestParam("pid") Long pid){
        return categoryService.getListlevl(pid);
    }

    /**
     * 获取所有三级分类数据  树型结构
      * @return
     */
    @RequestMapping("/cataList")
    public R cataList(){
        return R.ok().put("data",categoryService.getList());
    }

    @RequestMapping("/bid/{bid}")
    public List<CategoryEntity> getInfoByBrandId(@PathVariable Long bid){
       // ArrayList<CategoryEntity> categoryEntities = new ArrayList<>();
        //categoryEntities.add(categoryService.getInfoByBrandId(bid));
        return categoryService.getInfoByBrandId(bid);
    }

}
